package cn.study.vue_project_xxx.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.study.vue_project_xxx.common.exception.KnowException;
import cn.study.vue_project_xxx.entity.po.UserLogin;
import cn.study.vue_project_xxx.manager.UserLoginManager;
import cn.study.vue_project_xxx.service.LoginService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class LoginServiceImpl implements LoginService {

    @Resource
    UserLoginManager userLoginManager;

    @Override
    public void doLogin(UserLogin userLogin) {
        // 查询用户
        UserLogin queryUserLogin = userLoginManager.getUserLoginDetail(userLogin);
        if (Objects.isNull(queryUserLogin)) {
            throw new KnowException("当前用户不存在活不可用 !");
        }
        // 用户登录操作
        StpUtil.login(queryUserLogin.getLoginUserId());
    }

    @Override
    public void doLogOut(Long userId) {
        StpUtil.logout(userId);
    }
}
